#pragma once
#include <mzfc_inc.h>
#include <list>
#include <ddraw.h>
#include "MyButton.h"


#define BUTTON_COMMAND_SCENE_MIN		0
#define BUTTON_COMMAND_SCENE_MAINMENU	0
#define BUTTON_COMMAND_SCENE_FLIP		1
#define BUTTON_COMMAND_SCENE_ALPHA		2
#define BUTTON_COMMAND_SCENE_SPRITE		3
#define BUTTON_COMMAND_SCENE_MAX		3
#define BUTTON_COMMAND_CAPTURE			4
#define BUTTON_COMMAND_EXIT				5
#define BUTTON_COMMAND_MAX				5

class CMyScene
{
public:
	CMyScene(void);
	virtual ~CMyScene(void);
public:
	virtual void Init();
	virtual void RenderFrame(LPDIRECTDRAWSURFACE pDDSurface);
	virtual void OnLButtonDown( UINT fwKeys, int xPos, int yPos );
	virtual void OnLButtonUp( UINT fwKeys, int xPos, int yPos );
	virtual void OnMouseMove(UINT fwKeys, int xPos, int yPos);
	virtual void OnCommand(int nCommandId);
protected:
	bool ButtonDownEvent(UINT fwKeys, int xPos, int yPos);
	bool ButtonUpEvent(UINT fwKeys, int xPos, int yPos);
	bool ButtonMoveEvent(UINT fwKeys, int xPos, int yPos);

	virtual bool SceneDownEvent(UINT fwKeys, int xPos, int yPos);
	virtual bool SceneUpEvent(UINT fwKeys, int xPos, int yPos);
	virtual bool SceneMoveEvent(UINT fwKeys, int xPos, int yPos);

	std::list<CMyButton*>			m_buttonList;
	bool						m_bMouseDown;
};

class CMenuScene : public CMyScene
{
public:
	CMenuScene(void);
	virtual ~CMenuScene(void);
public:
	virtual void Init();
};

class CBlitScene : public CMyScene
{
public:
	CBlitScene(void);
	virtual ~CBlitScene(void);
public:
	virtual void Init();
	virtual void RenderFrame(LPDIRECTDRAWSURFACE pDDSurface);
protected:
	virtual bool SceneDownEvent(UINT fwKeys, int xPos, int yPos);
	virtual bool SceneUpEvent(UINT fwKeys, int xPos, int yPos);
	virtual bool SceneMoveEvent(UINT fwKeys, int xPos, int yPos);

	LPDIRECTDRAWSURFACE m_pDDSImg;
};

class CAlphaScene : public CMyScene
{
public:
	CAlphaScene(void);
	virtual ~CAlphaScene(void);
public:
	virtual void Init();
	virtual void RenderFrame(LPDIRECTDRAWSURFACE pDDSurface);
protected:
	virtual bool SceneDownEvent(UINT fwKeys, int xPos, int yPos);
	virtual bool SceneUpEvent(UINT fwKeys, int xPos, int yPos);
	virtual bool SceneMoveEvent(UINT fwKeys, int xPos, int yPos);

	LPDIRECTDRAWSURFACE m_pDDSImg;
};

typedef enum
{
	Down,
	LeftDown,
	Left,
	LeftUp,
	Up,
	RightUp,
	Right,
	RightDown,
}MoveDirection;

#define MIN_DIFF_STEP					5
#define MIN_MOVE_FRAME					1
#define MAX_MOVE_FRAME					4
#define SPRITE_COLOR_KEY				RGB(255, 0, 255)
#define SPRITE_HEIGHT					120
#define SPRITE_WIDTH					120
#define	SPRITE_FRAME_INTERVAL			7
#define	SPRITE_STEP_INTERVAL			3
#define FORTY_FIVE_DEGREE_STEP_RATE		0.707
#define FORTY_FIVE_DEGREE_STEP			CCommon::Round(FORTY_FIVE_DEGREE_STEP_RATE * SPRITE_STEP_INTERVAL)

class CSpriteScene : public CMyScene
{
public:
	CSpriteScene(void);
	virtual ~CSpriteScene(void);
public:
	virtual void Init();
	virtual void RenderFrame(LPDIRECTDRAWSURFACE pDDSurface);
protected:
	virtual bool SceneDownEvent(UINT fwKeys, int xPos, int yPos);
	virtual bool SceneUpEvent(UINT fwKeys, int xPos, int yPos);
	virtual bool SceneMoveEvent(UINT fwKeys, int xPos, int yPos);
	void ProceedMoveStep();
	void FixMoveStep();
	void StartMove(int xPos, int yPos);
	bool MoveOver();
	void DrawSprite(LPDIRECTDRAWSURFACE pDDSurface);
	void DrawBackGround(LPDIRECTDRAWSURFACE pDDSurface);

	MoveDirection	m_CurrentMoveDirection;
#ifdef _I8_MID_SDK_
	CPoint		m_CurrentMoveStep;
	CPoint		m_LastMovePos;
	CPoint		m_StandPos;
	CPoint		m_BackGroundPos;
#else
	CMzPoint		m_CurrentMoveStep;
	CMzPoint		m_LastMovePos;
	CMzPoint		m_StandPos;
	CMzPoint		m_BackGroundPos;
#endif
	LPDIRECTDRAWSURFACE m_pDDSSprite;
	LPDIRECTDRAWSURFACE m_pDDSBackGround;
	bool			m_bStartMove;
	int				m_nMoveFrame;

};

